package com.netprovider.user.service.baseinfo.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.netprovider.user.service.baseinfo.objects.User;

public final class DataLoader {
	
	
	private static List<User> userDataCache = new CopyOnWriteArrayList<User>();
	
	public static List<User> getUserData(){
		if (userDataCache == null || userDataCache.size() == 0) {
			try {
				loadUserData();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return userDataCache;
	}
	public static synchronized void loadUserData() throws Exception {
		if (userDataCache == null) {
			userDataCache = new ArrayList<User>();
		}
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		userDataCache.add(new User("001","John","Male",df.parse("2012-10-18")));
		userDataCache.add(new User("002","Mary","Female",df.parse("2012-10-21")));
		userDataCache.add(new User("003","Eric","Male",df.parse("2011-1-4")));
		userDataCache.add(new User("004","Frank","Male",df.parse("2014-3-18")));
		userDataCache.add(new User("005","Tina","Female",df.parse("2010-11-28")));
	}
	public static void main(String[] args) throws Exception{
		loadUserData();
        for (User user:userDataCache) {
        	System.out.println(user.toString());
        }
	}

}
